<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @method static withType(\App\Enums\TableType $type)
 */
class TableType extends Model
{
    use HasFactory;

    use SoftDeletes;

    protected $fillable = [
        'name', 'start_num', 'default_people_count', 'type', 'count', 'default_rule_id', 'store_id'
    ];

    public function costRules()
    {
        return $this->belongsToMany(CostRule::class);
    }

    public function defaultRule()
    {
        return $this->belongsTo(CostRule::class, 'default_rule_id');
    }

    public function tables()
    {
        return $this->hasMany(Table::class, 'type_id');
    }

    public function store()
    {
        return $this->belongsTo(Store::class);
    }

    public function scopeWithType($query, \App\Enums\TableType $type)
    {
        return $query->where('type', $type->value);
    }
}
